package net.wangds.web.controller;


import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import java.util.Optional;
import java.util.function.Function;

/**
 * 带有已登录用户信息的控制器抽象类.
 * @param <U> 用户类型.
 */
public abstract class AbstractKnownUserController<U> implements KnownUserController<U> {

    protected Function<HttpServletRequest, U> factoryFunc4KnownUser;

    @Autowired
    protected HttpServletRequest request;

    public U fetchKnownUser() {
        return Optional.of(factoryFunc4KnownUser).get().apply(Optional.of(request).get());
    }

}
